package simpleftp.client.control;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.Callable;
import simpleftp.client.gui.FTPClientWindow;

public class Downloader implements Callable<Boolean>{

	private SimpleFTP client;
	private String server;
	private String port;
	private FTPClientWindow wind;
	private String user;
	private String pass;
	private String remoteFilePath;
	private String localsavePath;

	public Downloader(String filePath, FTPClientWindow window, String server, String port,
			String user, String pass, String savePath) {
		this.remoteFilePath = filePath;
		this.server = server;
		this.port = port;
		this.wind = window;
		this.user = user;
		this.pass = pass;
		this.localsavePath = savePath;
		client = new SimpleFTP();
	}

	@Override
	public Boolean call() throws Exception {
		Boolean result = false;
		client.connect(server, Integer.parseInt(port), user, pass);
		result = client.retrv(remoteFilePath,localsavePath); //TODO TO BE CHANGED !!
		
		if (result) {
			wind.console.append("\nSuccessfully transfered file "
					+ remoteFilePath);
		} else {
			wind.console.append("\nFailed transfering file " + remoteFilePath);
		}
		return result;
	}
	
}
